<?php
// No direct access
defined ('_JEXEC') or die();

jimport ('joomla.form.formfield');

class JFormFieldWeb extends JFormField
{
	protected $type = 'Web';
	
	public function getInput()
	{
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('id, name');
		$query->from('#__sn_webs');
		$db->setQuery($query);
		
		$items = $db->loadObjectList();
		
		$options = array();
		
		foreach ($items as $item)
		{
			$options[$item->id] = $item->name;
		}
		
		return JHtml::_('select.genericlist', $options, $this->name, null, 'value', 'text', $this->value, $this->id);
	}
	
	public function getOptions()
	{
		$options = array();
		
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('id AS value, name AS text');
		$query->from('#__sn_webs');
		$db->setQuery($query);
		
		$options = $db->loadObjectList();
		
		// Check for a database error.
		if ($db->getErrorNum())
		{
			JError::raiseWarning(500, $db->getErrorMsg());
		}
		
		return $options;
	}
}